package com.yuanda.wordhot.repository;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.springframework.stereotype.Repository;

import com.yuanda.wordhot.entity.RoleEntity;

@Repository
public class RoleRepository extends HibernateGenericDAO<RoleEntity> implements IRepository<RoleEntity>{
	
	
	@SuppressWarnings("unchecked")
	public List<RoleEntity> getAllRoles(int start, int count) {
		Criteria criteria = sessionFactory.getCurrentSession().createCriteria(this.persistClass)
		.addOrder(Order.asc("roleId"));
		if(count != 0){
			criteria.setFirstResult(start).setMaxResults(count);
		}
		criteria.setComment("roleDao.getAllRoles");
		return criteria.list();
	}

	public long getTotalRoles() {
		return (Long)sessionFactory.getCurrentSession().createCriteria(this.persistClass)
				.setProjection(Projections.rowCount())
				.setCacheable(true)
				.setCacheRegion("roleDAO.getTotalRoles")
				.setComment("roleDAO.getTotalURoles")
				.uniqueResult();
	}
}
